package com.groupbuying.cheetah.order.storeMoneyFlow;

import com.groupbuying.cheetah.common.PageUtils;
import com.groupbuying.cheetah.common.Query;
import com.groupbuying.cheetah.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/* 够样优店管理后台---财务管理---商户流水管理 */
@RestController
@RequestMapping("/storeMoneyFlow")
public class StoreMoneyFlowController {

  @Autowired
  private StoreMoneyFlowDAO storeMoneyFlowDAO;

  @GetMapping("/list")
  public PageUtils list(@RequestParam Map<String, Object> params) {

    Query query = new Query(params);
    List<Map<String, String>> storeMoneyFlowList = storeMoneyFlowDAO.listStoreMoneyFlow(query);
    int total = storeMoneyFlowDAO.count(params);
    PageUtils pageUtils = new PageUtils(storeMoneyFlowList, total);
    return pageUtils;

  }


  @GetMapping("/export")
  public void refundManagement(@RequestParam Map<String, Object> params, HttpServletResponse response) {
    Query query = new Query(params);
    List<Map<String, String>> storeMoneyFlowList = storeMoneyFlowDAO.listStoreMoneyFlow(query);
    try {
      String[] header = { "订单编号", "买家名称","门店名称", "运营专员","下单时间","现金支付", "零钱支付","订单总金额", "支付方式","订单类型","支付状态"};
      Object[] columns = { "orderId", "customerId","storeName","operationSpecialist","orderTime","cashPayment","small_change","grossAmount","payType","order_type","order_state"};
      ExcelUtils.writeExcelByObject(storeMoneyFlowList, response, "商户流水账单", header, columns);
    } catch (Exception e) {
      e.printStackTrace();

    }
  }



}
